package com.katze.common;

import java.io.Serial;
import java.util.HashMap;

public class Message extends HashMap<String, Object> {

    @Serial
    private static final long serialVersionUID = -8713837118340960775L;

    private Message(){}

    public Message message(String... message) {
        if ( message.length != 0 ) {
            this.add("message", message[0]);
        }
        return this;
    }

    public Message data(Object data) {
        this.add("data", data);
        return this;
    }

    private Message code(ResponseStatus status) {
        this.add("code", status.value());
        this.add("type", status == ResponseStatus.OK? "success":"error");
        return this;
    }

    public Message add(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static Message ok(String... message){
        return new Message().code(ResponseStatus.OK).message(message);
    }

    public static Message error(String message) {
        return new Message().code(ResponseStatus.INTERNAL_SERVER_ERROR).message(message);
    }

    public static Message exception(ResponseStatus status) {
        return new Message().code(status).message(status.note());
    }

    public static Message exception(ResponseStatus status, String message) {
        return new Message().code(status).message(message);
    }
}
